home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / HPLJII.TRM < prev    next >
Text File  |  1992-03-25  |  9KB  |  320 lines

  1. /*
  2.  * $Id: hpljii.trm,v 3.26 92/03/24 22:34:57 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - hpljii.trm */
  6. /*
  7.  * Copyright (C) 1990, 1991, 1992   
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *  hpljii, hpdj
  25.  *
  26.  * AUTHORS
  27.  *  John Engels
  28.  *  Russell Lang
  29.  *  Maurice Castro
  30.  *
  31.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  32.  * 
  33.  */
  34.  
  35. /* The following HP laserjet series II driver uses generic bit mapped graphics
  36.    routines from bitmap.c to build up a bit map in memory.  The driver
  37.    interchanges colomns and lines in order to access entire lines
  38.    easily and returns the lines to get bits in the right order :
  39.    (x,y) -> (y,XMAX-1-x). */
  40. /* This interchange is done by calling b_makebitmap() with reversed 
  41.    xmax and ymax, and then setting b_rastermode to TRUE.  b_setpixel()
  42.    will then perform the interchange before each pixel is plotted */
  43. /* by John Engels JENGELS@BNANDP51.BITNET, inspired by the hpljet driver
  44.    of Jyrki Yli-Nokari */
  45.  
  46. #ifdef HPLJII
  47.  
  48. /* We define 4 different print qualities : 300ppi, 150ppi, 100ppi and
  49.    75ppi.  (Pixel size = 1, 2, 3, 4 dots) */
  50.  
  51. #define HPLJII_DPP (hplj_dpp)   /* dots per pixel */
  52. #define HPLJII_PPI (300/HPLJII_DPP) /* pixel per inch */
  53. /* make XMAX and YMAX a multiple of 8 */
  54. #define HPLJII_XMAX (8*(unsigned int)(xsize*1920/HPLJII_DPP/8.0+0.9))
  55. #define HPLJII_YMAX (8*(unsigned int)(ysize*1920/HPLJII_DPP/8.0+0.9))
  56.  
  57. #define HPLJII_VCHAR (HPLJII_PPI/6) /* Courier font with 6 lines per inch */
  58. #define HPLJII_HCHAR (HPLJII_PPI/10) /* Courier font with 10 caracters
  59.                                         per inch */
  60.  
  61. /* default values for term_tbl */
  62. #define HPLJII_75PPI_XMAX (1920/4)
  63. #define HPLJII_75PPI_YMAX (1920/4)
  64. #define HPLJII_75PPI_HCHAR (1920/4/6)
  65. #define HPLJII_75PPI_VCHAR (1920/4/10)
  66. #define HPLJII_75PPI_VTIC 5
  67. #define HPLJII_75PPI_HTIC 5
  68.  
  69.  
  70. #define HPLJII_PUSH_CURSOR fprintf(outfile,"\033&f0S") /* Save current
  71.                   cursor position */
  72. #define HPLJII_POP_CURSOR fprintf(outfile,"\033&f1S") /* Restore
  73.                   cursor position */
  74. #define HPLJII_COURIER fprintf(outfile,"\033(0N\033(s0p10.0h12.0v0s0b3T\033&l6D")
  75.          /* be sure to use courier font with 6lpi and 10cpi */
  76.  
  77. static int hplj_dpp=4;
  78. /* bm_pattern not appropriate for 300ppi graphics */
  79. static unsigned int b_300ppi_pattern[] = {0xffff, 0x1111,
  80.         0xffff, 0x3333, 0x0f0f, 0x3f3f, 0x0fff, 0x00ff, 0x33ff};
  81.  
  82. HPLJIIoptions()
  83. {
  84. char opt[4];
  85.  
  86. #define HPDJERROR "expecting dots per inch size 75, 100, 150 or 300"
  87.     if (!END_OF_COMMAND) {
  88.         if (token[c_token].length>3)
  89.             int_error(HPDJERROR,c_token);
  90.  
  91.         /* almost_equals() won't accept numbers - use strcmp() instead */
  92.         capture(opt,c_token,c_token);
  93.         if (!strcmp(opt,"75")) {
  94.                hplj_dpp = 4;
  95.         }
  96.         else if (!strcmp(opt,"100")) {
  97.                hplj_dpp = 3;
  98.         }
  99.         else if (!strcmp(opt,"150")) {
  100.                hplj_dpp = 2;
  101.         }
  102.         else if (!strcmp(opt,"300")) {
  103.                hplj_dpp = 1;
  104.         } else {
  105.             int_error(HPDJERROR,c_token);
  106.         }
  107.         c_token++;
  108.     }
  109.  
  110.     term_tbl[term].xmax = HPLJII_XMAX;
  111.     term_tbl[term].ymax = HPLJII_YMAX;
  112.     switch(hplj_dpp) {
  113.         case 1:
  114.             strcpy(term_options,"300");
  115.             term_tbl[term].v_tic = 15;
  116.             term_tbl[term].h_tic = 15;
  117.             break;
  118.         case 2:
  119.             strcpy(term_options,"150");
  120.             term_tbl[term].v_tic = 8;
  121.             term_tbl[term].h_tic = 8;
  122.             break;
  123.         case 3:
  124.             strcpy(term_options,"100");
  125.             term_tbl[term].v_tic = 6;
  126.             term_tbl[term].h_tic = 6;
  127.             break;
  128.         case 4:
  129.             strcpy(term_options,"75");
  130.             term_tbl[term].v_tic = 5;
  131.             term_tbl[term].h_tic = 5;
  132.             break;
  133.     }
  134. }
  135.  
  136.  
  137. HPLJIIinit()
  138. {
  139. #ifdef vms
  140.    reopen_binary();
  141. #endif /* vms */
  142. #ifdef PC
  143.    reopen_binary();
  144. #endif /* PC */
  145. }
  146.  
  147.  
  148. HPLJIIgraphics()
  149. {
  150.    term_tbl[term].v_char = HPLJII_VCHAR;
  151.    term_tbl[term].h_char = HPLJII_HCHAR;
  152.    HPLJII_COURIER;
  153.    HPLJII_PUSH_CURSOR;
  154.    /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  155.       setting b_rastermode to TRUE */
  156.    b_makebitmap(HPLJII_YMAX,HPLJII_XMAX,1);
  157.    b_rastermode = TRUE;
  158. }
  159.  
  160.  
  161. /* HPLJIItext by rjl - no compression */
  162. HPLJIItext()
  163. {
  164.   register int x,j,row;
  165.  
  166.    fprintf(outfile,"\033*t%dR", HPLJII_PPI);
  167.    HPLJII_POP_CURSOR;
  168.    fprintf(outfile, "\033*r1A");
  169.  
  170.    /* dump bitmap in raster mode */
  171.    for (x = b_xsize-1; x >= 0; x--) {
  172.       row = (b_ysize/8)-1;
  173.       fprintf(outfile, "\033*b0m%dW", b_ysize/8);
  174.       for (j = row; j >= 0; j--) {
  175.          (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  176.       }
  177.    }
  178.    fprintf(outfile, "\033*rB");
  179.  
  180.    b_freebitmap();
  181.  
  182. #ifndef vms  /* most vms spoolers add a formfeed character */
  183.    fprintf(outfile,"\f");
  184. #endif /* not vms */
  185. }
  186.  
  187.  
  188.  
  189. HPLJIIlinetype(linetype)
  190. int linetype;
  191. {
  192.  
  193.    if (hplj_dpp == 1) {
  194.       if (linetype>=7)
  195.           linetype %= 7;
  196.       /* b_pattern not appropriate for 300ppi graphics */
  197.       b_linemask = b_300ppi_pattern[linetype+2];
  198.       b_maskcount=0;
  199.    }
  200.    else {
  201.       b_setlinetype(linetype);
  202.    }
  203. }
  204.  
  205. #define HPLJIImove b_move
  206. #define HPLJIIvector b_vector
  207. #define HPLJIItext_angle b_text_angle
  208.  
  209. HPLJIIput_text(x,y,str)
  210. unsigned int x, y;
  211. char *str;
  212. {
  213.    switch (b_angle) {
  214.       case 0:
  215.          y -= HPLJII_VCHAR/5;
  216.          HPLJII_POP_CURSOR;
  217.          HPLJII_PUSH_CURSOR;
  218.          /* (0,0) is the upper left point of the paper */
  219.          fprintf(outfile, "\033*p%+dx%+dY", x*HPLJII_DPP
  220.                                          ,  (HPLJII_YMAX-y-1)*HPLJII_DPP );
  221.          fputs(str, outfile);
  222. /*       for (; *str; ++str, x += HPLJII_HCHAR)
  223.             HPLJIIputc (x, y, *str, b_angle);*/
  224.          break;
  225.       case 1:
  226.          y += (HPLJII_HCHAR-2*HPLJII_VCHAR)/2;
  227.          y += (HPLJII_VCHAR+HPLJII_HCHAR)*strlen(str)/2;
  228.          for (; *str; ++str, y -= HPLJII_VCHAR)
  229.             HPLJIIputc (x, y, *str, b_angle);
  230.          break;
  231.    }
  232. }
  233.  
  234. HPLJIIputc(x,y,c,angle)
  235. unsigned int x,y;
  236. int angle;
  237. char c;
  238. {
  239.    HPLJII_POP_CURSOR;
  240.    HPLJII_PUSH_CURSOR;
  241.    /* (0,0) is the upper left point of the paper */
  242.    fprintf(outfile, "\033*p%+dx%+dY", x*HPLJII_DPP
  243.                                    ,  (HPLJII_YMAX-y-1)*HPLJII_DPP );
  244.    fputc(c, outfile);
  245. }
  246.  
  247.  
  248. HPLJIIreset()
  249. {
  250. #ifdef vms
  251.    fflush_binary();
  252. #endif /* vms */
  253. }
  254.  
  255.  
  256. /* HP DeskJet routines */
  257. HPDJgraphics()
  258. {
  259.     switch(hplj_dpp) {
  260.         case 1:
  261.             b_charsize(FNT13X25);
  262.             term_tbl[term].v_char = FNT13X25_VCHAR;
  263.             term_tbl[term].h_char = FNT13X25_HCHAR;
  264.             break;
  265.         case 2:
  266.             b_charsize(FNT13X25);
  267.             term_tbl[term].v_char = FNT13X25_VCHAR;
  268.             term_tbl[term].h_char = FNT13X25_HCHAR;
  269.             break;
  270.         case 3:
  271.             b_charsize(FNT9X17);
  272.             term_tbl[term].v_char = FNT9X17_VCHAR;
  273.             term_tbl[term].h_char = FNT9X17_HCHAR;
  274.             break;
  275.         case 4:
  276.             b_charsize(FNT5X9);
  277.             term_tbl[term].v_char = FNT5X9_VCHAR;
  278.             term_tbl[term].h_char = FNT5X9_HCHAR;
  279.             break;
  280.     }
  281.     /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  282.     setting b_rastermode to TRUE */
  283.     b_makebitmap(HPLJII_YMAX,HPLJII_XMAX,1);
  284.     b_rastermode = TRUE;
  285. }
  286.  
  287.  
  288. /* 0 compression raster bitmap dump. Compatible with HP DeskJet 500
  289.    hopefully compatible with other HP Deskjet printers */
  290. HPDJtext()
  291. {
  292.   register int x,j,row;
  293.  
  294.    fprintf(outfile,"\033*b0M");
  295.    fprintf(outfile,"\033*t%dR", HPLJII_PPI);
  296.    fprintf(outfile, "\033*r0A");
  297.  
  298.    /* dump bitmap in raster mode */
  299.    for (x = b_xsize-1; x >= 0; x--) {
  300.       row = (b_ysize/8)-1;
  301.       fprintf(outfile, "\033*b%dW", b_ysize/8);
  302.       for (j = row; j >= 0; j--) {
  303.          (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  304.       }
  305.    }
  306.    fprintf(outfile, "\033*rbC");
  307.  
  308.    b_freebitmap();
  309.  
  310. #ifndef vms  /* most vms spoolers add a formfeed character */
  311.    fprintf(outfile,"\f");
  312. #endif /* not vms */
  313. }
  314.  
  315. #define HPDJtext_angle b_text_angle
  316. #define HPDJput_text b_put_text
  317.  
  318. #endif /* HPLJII */
  319.  
  320.